﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using pay.Entity;
using pay.BLL;
using System.Text;
using System.Text.RegularExpressions;
using Check;
public partial class shopping22 : System.Web.UI.Page
{

    public string str_sb = "";
    public string uname = "";
    public string tel = "";
    public string buylist = "";
    public string LinkMan = "";
    public string Msg = "";
    public string paytel = "";

    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {
            if (Session["EmoneyShopCard"] == null)
            {
                Response.Redirect("shopping0.aspx");
            }


            if (string.IsNullOrEmpty(Request["uname"]))
            {
                Response.Write("<script>alert('用户姓名不能为空!');window.close();</script>");
                Response.End();
                return;
            }
            if (string.IsNullOrEmpty(Request["tel"]))
            {
                Response.Write("<script>alert('联系电话不能为空！!');window.close();</script>");
                Response.End();
                return;

            }
            string reg_uname = Request["uname"].ToString().Trim().Replace(" ", "");
            bool flag0 = Verification.IsTszfc(reg_uname);
            if (flag0 == true)
            {
                uname = reg_uname;
            }
            else
            {
                Response.Write("<script>alert('用户姓名包含非法字符，请重新输入!');window.close();</script>");
                Response.End();
                return;
            }
            
            string reg_tel = Request["tel"].ToString().Trim().Replace(" ","");

            bool flag = Verification.IsMobileNum(reg_tel);
            bool flag1 = Verification.IsPhoneNum(reg_tel);
            if (flag == true || flag1 == true)
            {
                tel = reg_tel;
                paytel = tel.Substring(0, 3) + "****" + tel.Substring(7, 4);
            }
            else
            {
                Response.Write("<script>alert('请输入正确的电话或手机号码,例如:13916752109或0712-3614072');window.close();</script>");
                Response.End();
                return;

            }


            LinkMan = getLinkMan();
            buylist = BuyList().ToString();

            Session["uname"] = uname;
            Session["tel"] = tel;
            Session["Linkman"] = LinkMan;
            Session["SourceType"] = sourceType; //来源 

        }
    }

    public double tmpallAmount = 0;
    public StringBuilder BuyList()
    {
        StringBuilder sb = new StringBuilder();
        
        if (Session["EmoneyShopCard"] != null)
        {
            List<ShopCard> list = (List<ShopCard>)Session["EmoneyShopCard"];
            ProductBLL productbll = new ProductBLL();
             foreach (var c in list)
            {
                Product product = productbll.GetElementById(c.ProductId);
                c.ProductName = product.Productname;
                c.Price = product.Nowprice.Value;
                tmpallAmount += c.Amount;

                sb.AppendLine("<ul class=\"product_zong\">");
                sb.AppendLine("<li class=\"product_zong1\">" + c.ProductName + "</li>");
                sb.AppendLine("<li class=\"product_zong2 pz_23\" id=\"price\">" + c.Price + "元</li>");
                sb.AppendLine("<li class=\"product_zong2 pz_24\">");
                sb.AppendLine("" + c.Count + "件");
                sb.AppendLine("</li>");

                sb.AppendLine("<li class=\"product_zong3\" id=\"amount" + c.ProductId + "\">" + c.Amount + "元</li>");
                sb.AppendLine("</ul>");



            }

        }

        return sb;
    }

 
    public string getLinkMan()
    {
        if (Request["LinkMan"] != null)
        {
            LinkMan = Request["LinkMan"].ToString();
        }

        return LinkMan;
    }

    public int sourceType
    {
        get
        {
            if (string.IsNullOrEmpty(Request["sourceType"]))
            {
                return 1;
            }

            return Convert.ToInt32(Request["sourceType"].ToString());

        }
    }//来源(1-网页、2-软件)

}